<template>
  <div class="content-box">
    <nav-title title="紧急联系人" />
    <div class="line">
      <span class="important">*</span>
      <div class="label">姓名</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="emergen.cName">
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">性别</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" :options="sexVal" v-model="emergen.cTactPerSex"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">与本人关系</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" :options="relVal" v-model="emergen.cRelationTact"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">工作单位</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="emergen.cCompany">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">办公电话</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="emergen.cPhone2">
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">手机电话</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="emergen.cPhone1">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">住宅电话</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="emergen.cPhone">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">联系地址</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="emergen.cAddress">
      </div>
    </div>

    <div class="bsbtn" @click="save">
      保存
    </div>
  </div>

</template>

<script>
import { Datetime, Group, PopupRadio } from 'vux'
import { getDicItem,saveEmergent } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
    Datetime, Group, PopupRadio
  },
  mounted(){
    //获取字典
    this.getsexDic()
    this.getrelDic()

    if(this.$store.state.hid){
      this.emergen.rsHireId = this.$store.state.hid
    }
  },
  data() {
    return {
      emergen:{
        rsHireId: '',
      },
      sexVal:[],
      relVal:[],
    }
  },
  created() {
    this.getEmers()
  },
  methods: {
    save() {
      const that = this
      if(that.emergen.cName == '' || that.emergen.cName == undefined){
        this.$vux.alert.show({
          title: '警告',
          content: '请输入姓名'
        });
        return;
      }
      if(that.emergen.cTactPerSex == ''|| that.emergen.cTactPerSex == undefined){
        this.$vux.alert.show({
          title: '警告',
          content: '请选择性别'
        });
        return;
      }
      if(that.emergen.cRelationTact == ''|| that.emergen.cRelationTact == undefined){
        this.$vux.alert.show({
          title: '警告',
          content: '请选择关系'
        });
        return;
      }
      if(that.emergen.cPhone1 == '' || that.emergen.cPhone1 == undefined){
        this.$vux.alert.show({
          title: '警告',
          content: '请输入电话'
        });
        return;
      }
      saveEmergent(json2Form(that.emergen)).then(res => {
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          // 显示
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })

        }else{
          // 显示
          this.$vux.alert.show({
            title: '',
            content: res.retMsg
          })
        }
        console.log(res)
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })

    },

      //性别
      getsexDic(){
        this.sexVal = []
        let params = {
          fileName: 'SEX'
        }
        getDicItem(params).then(res => {
          res.retData.forEach((val) => {
            this.sexVal.push({value: val.xlatshortname, key: val.fieldvalue})
          });
        }).catch(res => {

        })
      },

      //关系
      getrelDic(){
        this.sexVal = []
        let params = {
          fileName: 'C_RELATION_TACT'
        }
        getDicItem(params).then(res => {
          res.retData.forEach((val) => {
            this.relVal.push({value: val.xlatshortname, key: val.fieldvalue})
          });
        }).catch(res => {

        })
      },

    getEmers() {
      this.emergen = this.$route.params.emeg
    }
  }
}
</script>
<style type="text/scss" lang="scss">
@import "./editinfo";
</style>
